<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of regulamento
 *
 * @author Leonardo Lino
 */
class regulamento extends CI_Controller {

    private $smarty;

    public function __construct() {
        parent::__construct();
        $this->load->library('session');
        $session_id = $this->session->userdata('session_id');
        require_once 'smartyLoader.php';
        $this->smarty = $smarty;
        $this->user->isAccessBackOffice($this->smarty);
        $this->load->model('regulamentoModel');
    }

    public function index() {
        $this->load->model('epocaModel');

        $regulamentos = $this->regulamentoModel->loadAll();
        if ($regulamentos == null) {
            $this->smarty->assign("vazio", 0);
        } else {
            $this->smarty->assign("vazio", 1);
        }

        $epocas = $this->epocaModel->loadAll();

        if ($epocas == null)
            $this->smarty->assign("notok", true);

        $this->smarty->assign("epocas", $epocas);
        $this->smarty->assign("regulamentos", $regulamentos);
        $this->smarty->assign("templateActivo", "regulamento.tpl.html");
        $this->smarty->display('admin/header.tpl.html');
        $this->smarty->display('admin/main.tpl.html');
        $this->smarty->display('admin/footer.tpl.html');
    }

    public function novo() {

        $state = $_POST['state'];
        if ($state == "1") {
            //novo($texto, $eid)
            $resultado = $this->regulamentoModel->novo($_POST['texto'], $_POST['id_epoca']);
            $this->index();
        } else {
            $resultado = $this->regulamentoModel->update($_POST['vid'], $_POST['texto'], $_POST['id_epoca']);
            $this->index();
        }
    }

    public function delete() {
        $resultado = $this->regulamentoModel->deleteFromId($_GET['vid']);
        $this->index();
    }

}

?>